package com.backend.system.common;

import com.backend.system.common.enums.ErrorEnum;
import lombok.Getter;

import java.io.Serial;

/**
 * 自定义异常
 *
 * @author backend-manage
 */
@Getter
public class CustomException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = 5221984203723243917L;

    private ErrorCode error;
    private String code;

    public CustomException(ErrorCode error) {
        super(error.getMessage());
        this.error = error;
        this.code = error.getCode();
    }


    public CustomException(String message) {
        super(message);
    }

    public static CustomException argsError(String message) {
        CustomException customException = new CustomException(message);
        customException.code = ErrorEnum.ARGS_ERROR.getCode();
        return customException;
    }
}
